﻿using System.Data;
using Demo.CommonBase.DTO.Infos;
using Demo.CommonBase.Logging;
using System.Collections.Generic;
using System.Linq;
using System;
using Demo.CommonBase.Exceptions;
using System.Reflection;
namespace Demo.CommonBase.Integration.DAO.IntegrationComponents.Mappings
{
    public static class CommonComboBoxDAOMapping
    {
        public static CommonComboBoxPagingInfo GetDataByNameMapping(DataSet ds)
        {
            CommonComboBoxPagingInfo result;
            DataTable dt;
            try
            {
                Logger.Info();
                dt = ds.Tables[0];
                result = new CommonComboBoxPagingInfo();
                result.Pagination = new PaginationInfo();
                result.Pagination.TotalCount = (int)dt.Rows[0]["ToltalReg"];

                dt = ds.Tables[1];

                result.DataList = (from contact in dt.AsEnumerable()
                                   select new CommonComboBoxInfo
                                   {
                                       Id = contact.Field<int>("id"),
                                       Name = contact.Field<string>("nombre")
                                   }).ToList();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }

            return result;

        }
    }
}
